/*
 * 	Flan.Zeng 2011-2016	http://git.oschina.net/signup?inviter=flan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.flan.stock.activity;

import java.util.ArrayList;
import java.util.List;

import com.flan.stock.R;
import com.flan.stock.adapter.QuotationFragmentAdapter;
import com.flan.stock.fragment.FragmentNavigatorA;
import com.flan.stock.fragment.FragmentQuotationHs;
import com.flan.stock.view.AnimationTabWidget;
import com.flan.stock.view.FooterMenuView;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;

/**
 * 底部主菜单列表中显示“行情”菜单的窗口
 * @author flan
 * @date   2015年10月27日
 */
public class QuotationActivity extends FragmentActivity implements OnPageChangeListener{
	
	private ViewPager viewPager;
	private AnimationTabWidget tabWidget;
	private Intent intent;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_quotation);
		
		//初始化底部菜单控件
		FooterMenuView menu = (FooterMenuView) this.findViewById(R.id.footer_menu);
		menu.setCurrentMenu(R.id.menu_hangqing);
		menu.setOnTouchListener(menu.new MenuOnTouchListener());
		
		viewPager = (ViewPager) this.findViewById(R.id.vp_fragment);
		//viewPager.setAdapter(new WelcomeAdapter(getPagers()));
		viewPager.setAdapter(new QuotationFragmentAdapter(getSupportFragmentManager(),createFragments()));
		viewPager.addOnPageChangeListener(this);
		
		//初始化animationTabWidget控件
		tabWidget = (AnimationTabWidget) this.findViewById(R.id.tab_widget);
		tabWidget.setOnClickListener(tabWidget);
		tabWidget.setViewPager(viewPager);
		
		intent = this.getIntent();
		viewPager.setCurrentItem(intent.getIntExtra("currentItem", 0));
		
	}
	
	public void tabWidgetIsVisable(boolean isVisable){
		
		if(isVisable){
			tabWidget.setVisibility(View.VISIBLE);
		}else {
			tabWidget.setVisibility(View.GONE);
		}
	}
	
	private ArrayList<Fragment> createFragments(){
		
		ArrayList<Fragment> list = new ArrayList<>();
		
		FragmentNavigatorA f1 = new FragmentNavigatorA(this);
		FragmentQuotationHs f2 = new FragmentQuotationHs(this);
		
		list.add(f1);
		list.add(f2);
		
		return list;
	}
	
	@SuppressLint("InflateParams")
	private List<View> getPagers(){
			
		List<View> viewList = new ArrayList<>();
		LayoutInflater inflater = this.getLayoutInflater();
		
		View pager1 = inflater.inflate(R.layout.item_welcome_a, null);
		View pager2 = inflater.inflate(R.layout.item_welcome_b, null);
		View pager3 = inflater.inflate(R.layout.item_welcome_c, null);
		View pager4 = inflater.inflate(R.layout.item_welcome_a, null);
		View pager5 = inflater.inflate(R.layout.item_welcome_b, null);
		
		
		viewList.add(pager1);
		viewList.add(pager2);
		viewList.add(pager3);
		viewList.add(pager4);
		viewList.add(pager5);
		
		return viewList;
	}


	@Override
	public void onPageScrollStateChanged(int arg0) {
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
	}

	@Override
	public void onPageSelected(int position) {
		
		tabWidget.setCurrentTab(position);
		
	}

}

















